/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.easyidea.its.domain.model.system;

import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.easyidea.its.domain.model.BaseEntity;

/**
 * 
 * @author hukn
 */
@Entity
@Table(name = "Department")
public class Department extends BaseEntity {
	private static final long serialVersionUID = 1L;

	/**
	 * identify -- auto_increment
	 */
	// protected Integer id = new Integer("-1");
	private int departmentCode;

	private String departmentType;

	private String departmentName;

	private String departmentAddress;

	private String telephone;

	private List<Department> departmentList;

	private Department parentId;

	private List<PassPort> passPorts;

	public Department() {
	}

	public Department(Integer id, int departmentCode) {
		this.id = id;
		this.departmentCode = departmentCode;
	}

	@Basic(optional = false)
	@Column(name = "departmentCode")
	public int getDepartmentCode() {
		return departmentCode;
	}

	public void setDepartmentCode(int departmentCode) {
		this.departmentCode = departmentCode;
	}

	@Column(name = "departmentType")
	public String getDepartmentType() {
		return departmentType;
	}

	public void setDepartmentType(String departmentType) {
		this.departmentType = departmentType;
	}

	@Column(name = "departmentName")
	public String getDepartmentName() {
		return departmentName;
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	@Column(name = "departmentAddress")
	public String getDepartmentAddress() {
		return departmentAddress;
	}

	public void setDepartmentAddress(String departmentAddress) {
		this.departmentAddress = departmentAddress;
	}

	@Column(name = "telephone")
	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	@OneToMany(mappedBy = "parentId", fetch = FetchType.LAZY)
	public List<Department> getDepartmentList() {
		return departmentList;
	}

	public void setDepartmentList(List<Department> departmentList) {
		this.departmentList = departmentList;
	}

	@JoinColumn(name = "parent_id", referencedColumnName = "id")
	@ManyToOne(fetch = FetchType.LAZY)
	public Department getParentId() {
		return parentId;
	}

	public void setParentId(Department parentId) {
		this.parentId = parentId;
	}

	@OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
	@JoinColumn(name = "department_id")
	public List<PassPort> getPassPorts() {
		return passPorts;
	}

	public void setPassPorts(List<PassPort> passPorts) {
		this.passPorts = passPorts;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof Department)) {
			return false;
		}
		Department other = (Department) object;
		if ((this.id == null && other.id != null)
				|| (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "com.easyidea.its.domain.model.system.Department[id=" + id + "]";
	}

}
